import java.awt.*;
import java.util.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class View extends JFrame {
	Map<String,String> rooms=new HashMap<String, String>();
	
	//Swing components
	private JTabbedPane tabs;
	private JPanel settings;
	private JComboBox roomlist;
	private JTextField roompath;
	private JPanel home;
	private JPanel graph;
	private JPanel stat;
	private JButton simport;
	private JButton refreshstat;
	private JButton addnewroom;
	private JComboBox statrooms;
	private JComboBox statstakes;
	private JComboBox statplayers;
	private JLabel sumwin;
	private JLabel sumbuyin;
	private JLabel sumfee;
	private JLabel sumprofit;
	private JLabel gamecount;
	private JLabel roi;
	private JLabel hup;
	
	public View(Control control)
	{
		setTitle("Sit & Go stAts");
		setSize(640, 320);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		tabs=new JTabbedPane();
		
		//Settings tab
		settings=new JPanel();
		roomlist=new JComboBox();
		roompath=new JTextField();
		addnewroom=new JButton("Add new");
		roompath.setMinimumSize(new Dimension(50, roompath.getHeight()));
		roomlist.addActionListener(control);
		addnewroom.addActionListener(control);
		settings.add(roomlist);
		settings.add(roompath);
		settings.add(addnewroom);
		
		//Home tab
		home=new JPanel();
		simport=new JButton("Start Import!");
		simport.addActionListener(control);
		simport.setName("simport");
		home.add(simport);
		
		//Graph tab
		graph=new JPanel();
		
		//Stats tab
		stat=new JPanel();
		roi=new JLabel("s");
		sumwin=new JLabel("s");
		sumfee=new JLabel("s");
		sumbuyin=new JLabel("s");
		sumprofit=new JLabel("s");
		gamecount=new JLabel("s");
		hup=new JLabel("s");
		statrooms=new JComboBox();
		statstakes=new JComboBox();
		statplayers=new JComboBox();
		refreshstat=new JButton("Refresh");
		stat.setLayout(new GridBagLayout());
		refreshstat.addActionListener(control);
		GridBagConstraints gbc=new GridBagConstraints();
		statplayers.addItem("All");
		statrooms.addItem("All");
		statstakes.addItem("All");
		gbc.anchor=GridBagConstraints.LINE_START;
		gbc.gridy=0;
		stat.add(refreshstat,gbc);
		gbc.gridx=0;
		gbc.gridy=1;
		gbc.insets.right=5;
		stat.add(new JLabel("Room:"),gbc);
		gbc.gridx=1;
		gbc.insets.right=20;
		stat.add(statrooms,gbc);
		gbc.gridx=2;
		gbc.insets.right=5;
		stat.add(new JLabel("Stake:"),gbc);
		gbc.gridx=3;
		gbc.insets.right=20;
		stat.add(statstakes,gbc);
		gbc.gridx=4;
		gbc.insets.right=5;
		stat.add(new JLabel("Players:"),gbc);
		gbc.gridx=5;
		gbc.insets.right=0;
		stat.add(statplayers,gbc);
		gbc.gridx=0;
		gbc.gridy=2;
		gbc.insets.right=5;
		stat.add(new JLabel("ROI%:"),gbc);
		gbc.gridx=1;
		stat.add(roi,gbc);
		gbc.gridx=0;
		gbc.gridy=3;
		gbc.insets.right=5;
		stat.add(new JLabel("Sum Buyin:"),gbc);
		gbc.gridx=1;
		stat.add(sumbuyin,gbc);
		gbc.gridx=0;
		gbc.gridy=4;
		gbc.insets.right=5;
		stat.add(new JLabel("Sum Fee:"),gbc);
		gbc.gridx=1;
		stat.add(sumfee,gbc);
		gbc.gridx=0;
		gbc.gridy=5;
		gbc.insets.right=5;
		stat.add(new JLabel("Sum profit:"),gbc);
		gbc.gridx=1;
		stat.add(sumprofit,gbc);
		gbc.gridx=0;
		gbc.gridy=6;
		gbc.insets.right=5;
		stat.add(new JLabel("Sum Wins:"),gbc);
		gbc.gridx=1;
		stat.add(sumwin,gbc);
		gbc.gridx=0;
		gbc.gridy=7;
		gbc.insets.right=5;
		stat.add(new JLabel("Gamecount:"),gbc);
		gbc.gridx=1;
		stat.add(gamecount,gbc);
		gbc.gridx=0;
		gbc.gridy=8;
		gbc.insets.right=5;
		stat.add(new JLabel("HU%:"),gbc);
		gbc.gridx=1;
		stat.add(hup,gbc);
		statrooms.addActionListener(control);
		statstakes.addActionListener(control);
		statplayers.addActionListener(control);
		
		//Adding tabs
		tabs.addTab("Home", home);
		tabs.addTab("Statistics", stat);
		tabs.addTab("Graph", graph);
		tabs.addTab("Settings",settings);
		this.add(tabs);		
	}

	public void setStats(Map<String, String> rooms)
	{
		sumwin.setText(rooms.get("sumwin"));
		sumbuyin.setText(rooms.get("sumbuyin"));
		sumfee.setText(rooms.get("sumfee"));
		sumprofit.setText(rooms.get("sumprofit"));
		gamecount.setText(rooms.get("gamecount"));
		roi.setText(rooms.get("roi")+"%");
		hup.setText(rooms.get("hup")+"%");
	}
	public void setRooms(Map<String, String> rooms) {
		this.rooms = rooms;
		for(String s: rooms.keySet()){
			roomlist.addItem(s);
			statrooms.addItem(s);
		}
	}
	
	public Map<String, String> getRooms(){
		return rooms;
	}
	
	public JTabbedPane getTabs() {
		return tabs;
	}

	public JPanel getSettings() {
		return settings;
	}

	public JComboBox getRoomlist() {
		return roomlist;
	}

	public JPanel getHome() {
		return home;
	}

	public JPanel getGraph() {
		return graph;
	}

	public JTextField getRoompath() {
		return roompath;
	}

	public void setRoompath(String roompath) {
		this.roompath.setText(rooms.get(roompath));
	}
	
	public void setStatStakes(Set<String> s){
		statstakes.removeAllItems();
		statstakes.addItem("All Stakes");
		for(String sr:s){
			statstakes.addItem(sr);
		}
	}

	public void setStatPlayers(Set<String> s){
		statplayers.removeAllItems();
		statplayers.addItem("All Players");
		for(String sr:s){
			statplayers.addItem(sr);
		}
	}
}
